package com.mission.game.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import com.mission.game.components.Statusable.Status;

public class Game implements Serializable {

	private static final long serialVersionUID = -5308639376820947320L;
	protected static final int NOT_FOUND = -1;

	public enum Visibility {
		PUBLIC, PRIVATE, GLOBAL;
	}

	private String _name;
	private Calendar _startDate;
	private Boolean _isActive;
	private Visibility _visibility;
	private HashMap<String, Mission> _missionList;
	private List<User> _players;
	private String _description;
	
	// TODO Add groups later.
	public Game(String name, String description, 
			Calendar startDate, Boolean isActive, Visibility visibility) {
		super();
		_name = name;
		setDescription(description);
		_startDate = startDate;
		_isActive = isActive;
		_visibility = visibility;
		_missionList = new HashMap<String, Mission>();
		_players = new Vector<User>();
	}

	public String getName() {
		return _name;
	}

	public void setName(String name) {
		_name = name;
	}

	public Calendar getStartDate() {
		return _startDate;
	}

	public void setStartDate(Calendar startDate) {
		_startDate = startDate;
	}

	public Boolean isActive() {
		return _isActive;
	}

	public void setIsActive(Boolean isActive) {
		_isActive = isActive;
	}

	public Visibility getVisibility() {
		return _visibility;
	}

	public void setVisibility(Visibility visibility) {
		_visibility = visibility;
	}

	public HashMap<String, Mission> getMissions() {
		return _missionList;
	}
	
	public ArrayList<Mission> getMissionList() {
		return new ArrayList<Mission>(_missionList.values());
	}

	public void setMissions(HashMap<String, Mission> missionList) {
		_missionList = missionList;
	}

	public List<User> getPlayers() {
		return _players;
	}

	public void setPlayers(List<User> players) {
		_players = players;
	}

	public void addMission(Mission m) {
		_missionList.put(m._name, m);
	}

	public Set<String> getMissionNames() {
		return _missionList.keySet();
	}

	public void removeMission(String missionName) {
		_missionList.remove(missionName);
	}

	public void setDescription(String description) {
		_description = description;
	}

	public String getDescription() {
		return _description;
	}

	public void updateMission(Mission mission) {
		_missionList.put(mission._name, mission);
	}

	public int getScore() {
		int score = 0;
		for(Mission m: _missionList.values())
			for(Task t: m.getTasks())
				if (t.getStatus() == Status.COMPLETED)
					score += t.getScore();
		return score;
	}
}
